using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using System.Data.SqlClient;

namespace Report.PhieuA
{
    public partial class UcA37 : DevExpress.XtraEditors.XtraUserControl
    {
        public UcA37()
        {
            InitializeComponent();
        }

        private void UcA37_Load(object sender, EventArgs e)
        {
            DataTable dtA37 = new DsReportX.Table2ColDataTable();
            dtA37 = CalculateData(dtA37);
            gridControlA.DataSource = dtA37;
        }

        DataTable CalculateData(DataTable dt)
        {
            SqlConnection con = new SqlConnection(GeneralLibs.LocalSettings.ConnectString);
            SqlCommand cmd = con.CreateCommand();
            SqlDataAdapter da = new SqlDataAdapter();
            try
            {
                con.Open();
                cmd.CommandText = "SELECT Co Number1, Khong Number2  FROM \n" +
                                "( SELECT COUNT(CauTraLoiFIX1) Co FROM Phieu A INNER JOIN ChiTietPhieu B ON A.ID = B.PhieuID \n" +
                                "WHERE A.LoaiPhieu = 'PhieuA' AND MaCau = 21 AND CauTraLoiFIX1 = 1 \n" +
                                ") a, ( \n" +
                                "SELECT COUNT(CauTraLoiFIX1) Khong FROM Phieu A INNER JOIN ChiTietPhieu B ON A.ID = B.PhieuID \n" +
                                "WHERE A.LoaiPhieu = 'PhieuA' AND MaCau = 21 AND CauTraLoiFIX1 = 2 \n" +
                                ") b";
                da.SelectCommand = cmd;
                da.Fill(dt);
                return dt;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                return null;
            }
            finally
            {
                con.Close();
            }
        }
    }
}
